import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-09-13
 * Time: 17:54
 */
class TestH1 {
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int tail = m+n-1;
        int cur = 0;
        int p1 = m-1, p2 = n-1;
        while(p1 >= 0 || p2 >= 0) {
            if(p1 == -1) {
                cur = nums2[p2--];
            }else if(p2 == -1) {
                cur = nums1[p1--];
                // 倒序不要搞错了
            }else if(nums1[p1] > nums2[p2]) {
                cur = nums1[p1--];
            }else {
                cur = nums2[p2--];
            }
            nums1[tail--] = cur;
        }
    }

    public static void main(String[] args) {
        int[] num1 = {1,2,5,0,0,0,0};
        int[] num2 = {4,6,9,10};
        int m = 3, n = 4;
        merge(num1,m,num2,n);
        System.out.println(Arrays.toString(num1));
    }
}

